package com.guomei.controller;

import com.guomei.bean.Certificate;
import com.guomei.bean.certificate.vo.CertficateDTO;
import com.guomei.service.CertificateService;
import com.guomei.utils.PageData;
import com.guomei.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api1/certificate")
@Slf4j
public class CertificateController {
    @Autowired
    private CertificateService certificateService;

    /**
     * 创建证书
     * @param certificate 证书对象
     * @return 结果对象
     */
    @PostMapping("/add")
    public Result<?> createCertificate(@RequestBody Certificate certificate) {
        return certificateService.createCertificate(certificate);
    }

    /**
     * 查询证书
     * @param certificate 证书对象
     * @return 结果对象
     */
    @PostMapping("/select")
    public Result<?> select(@RequestBody CertficateDTO certificate) {
        log.info("查询证书信息入参：{}", certificate);
        try {
            return certificateService.selectByCondition(certificate);
        } catch (Exception e) {
            log.info("查询证书信息失败", e);
            return Result.fail("查询证书信息失败");
        }
    }



    /**
     * 更新证书信息
     * @param certificate 证书对象
     * @return 结果对象
     */
    @PostMapping("/update")
    public Result<?> updateCertificate(@RequestBody Certificate certificate) {
        return certificateService.updateCertificate(certificate);
    }

    /**
     * 删除证书
     * @param id 证书ID
     * @return 结果对象
     */
    @DeleteMapping("/{id}")
    public Result<?> deleteCertificate(@PathVariable Long id) {
        return certificateService.deleteCertificate(id);
    }
}
